angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])

  .run(function ($ionicPlatform, $rootScope, $ionicHistory, $state) {
    $ionicPlatform.ready(function () {
      if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        cordova.plugins.Keyboard.disableScroll(true);
      }
      if (window.StatusBar) {
        StatusBar.styleDefault();
      }
    });
  })

  .config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
    $ionicConfigProvider.platform.ios.tabs.style('standard');
    $ionicConfigProvider.platform.ios.tabs.position('bottom');
    $ionicConfigProvider.platform.android.tabs.style('standard');
    $ionicConfigProvider.platform.android.tabs.position('bottom');

    $ionicConfigProvider.platform.ios.navBar.alignTitle('center');
    $ionicConfigProvider.platform.android.navBar.alignTitle('center');

    $ionicConfigProvider.platform.ios.backButton.previousTitleText('').icon('ion-ios-arrow-thin-left');
    $ionicConfigProvider.platform.android.backButton.previousTitleText('').icon('ion-android-arrow-back');

    $ionicConfigProvider.platform.ios.views.transition('ios');
    $ionicConfigProvider.platform.android.views.transition('android');

    //主页
    $stateProvider
      .state('index',{
        url: '/index',
        templateUrl: 'html/index/index.html'
      })

    //订餐
    $stateProvider
      .state('shop-list',{
        url: '/shop/list',
        templateUrl: 'html/shops/shop-list.html',
        controller: 'ShopListCtrl'
      })
      .state('shop-detail',{
        url: '/shop/detail/:shopId',
        templateUrl: 'html/shops/shop-detail.html',
        controller: 'ShopDetailCtrl'
      })
      .state('shop-order',{
        url: '/shop/order',
        templateUrl: 'html/shops/shop-order.html',
        controller: 'ShopOrderCtrl'
      });

    //订单
    $stateProvider
      .state('order-list',{
        url: '/order/list',
        templateUrl: 'html/orders/order-list.html',
        controller: 'OrderListCtrl'
      })
      .state('order-detail',{
        url: '/order/list/detail/:orderId',
        templateUrl: 'html/orders/order-detail.html',
        controller: 'OrderListDetailCtrl'
      });

    //个人中心
    $stateProvider
      .state('account',{
        url: '/account',
        templateUrl: 'html/account/account.html',
        controller: 'AccountCtrl'
      })
      .state('account-detail',{
        url: '/account/detail/:userId',
        templateUrl: 'html/account/account-detail.html',
        controller: 'AccountDetailCtrl'
      });

    //收货地址
    $stateProvider
      .state('address-list',{
        url: '/address/list',
        templateUrl: 'html/address/address-list.html',
        controller: 'AddressListCtrl'
      })
      .state('address-edit',{
        url: '/address/edit/:addressId',
        templateUrl: 'html/address/address-edit.html',
        controller: 'AddressEditCtrl'
      });

    //已完成订单
    $stateProvider
      .state('completedOrder-list',{
        url: '/completedOrder/list',
        templateUrl: 'html/completedorder/completedOrder-list.html',
        controller: 'CompletedOrderListCtrl'
      })
      .state('completedorder-detail',{
        url: '/completedorder/detail/:orderId',
        templateUrl: 'html/completedorder/completedorder-detail.html',
        controller: 'CompletedOrderDetailCtrl'
      });

    //错误界面
    $stateProvider
      .state('error',{
        url: '/error',
        templateUrl: 'html/error/error.html'
      });

    $urlRouterProvider.otherwise('/index');
  })
